<template>
  <div class="Voucher">
    <div class="titles">积分券</div>
    <div class="demo-text" v-if="active1 === 0">
      <!-- 双倍积分券 -->
      <div class="no-use" v-for="item in items" :key="item.index">
        <div class="title">{{item.name}}</div>
        <div class="contant">
          <div class="jf">
            <p>{{item.cate_top}}</p>
            <p>{{item.cate_bottom}}</p>
          </div>
          <div class="js">{{item.content}}</div>
        </div>
        <div class="bottom">
          <div>{{item.remark}}</div>
          <button v-if="used==1">立即使用</button>
          <img v-if="used==2" src="../assets/use.png" alt="">
          <img v-if="used==3" src="../assets/used.png" alt="">
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import http from "../utils/http";
export default {
  name: "Voucher",
  data() {
    return {
      active1: 0,
      items: [],
      used: 1
    };
  },
  created() {
    var str = location.href;
    // console.log('urlStr',str)
    // var reg = /sign\/(.*)#/i
    // var res = str.search(reg)
    var start = str.search("sign/");
    var end = str.search("#");
    var start2 = parseInt(start + 5);
    var res = str.substring(start2, end);
    // console.log('res',res)
    var that = this;
    // 奖券
    http
      .post("Zmhf/index", {
        key: "be15d4ca913c91494cb4f9cd6ce317c6",
        sign: res,
        type: "getUserTicketList"
      })
      .then(function(response) {
        // console.log("response", response);
        if (response.errcode == 0) {
          // 0是已使用
          for (var i = 0; i < response.data.rows.length; i++) {
            if (response.data.rows[i].status == "可使用") {
              that.used = 1
            } else if (response.data.rows[i].status == "已使用") {
              that.used = 2
            } else {
              that.used = 3
            }
          }
          that.items = response.data.rows;
        } else {
          console.log("response", response.msg);
        }
      })
      .catch(function(error) {
        // console.log("error", error);
      });
  },
  methods: {}
};
</script>
<style lang="scss" scoped>
.Voucher {
  width: 100%;
  height: 100vh;
  overflow: scroll;
  background-color: #efefef;
  .titles {
    width: 100%;
    height: 3rem;
    line-height: 3rem;
    text-align: center;
    font-size: 1.1rem;
    background-color: #fff;
  }
  .demo-text {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
    margin-top: 1rem;
    margin-bottom: 1rem;
    .no-use {
      position: relative;
      margin-top: 1rem;
      width: 90%;
      height: 12rem;
      background-image: url("../assets/sbq.png");
      background-repeat: no-repeat;
      background-size: 100% 100%;
      .title {
        padding-left: 1rem;
        width: 100%;
        height: 3.5rem;
        font-size: 1rem;
        color: #fff;
        text-align: left;
        line-height: 3.5rem;
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
      }
      .contant {
        display: inline-flex;
        align-items: flex-start;
        width: 100%;
        height: 5rem;
        .jf {
          width: 30%;
          height: 4rem;
          p {
            padding-left: 1rem;
            text-align: left;
            color: #fff;
            font-size: 0.8rem;
          }
          p:first-child {
            font-size: 1.3rem;
          }
        }
        .js {
          padding: 0 1rem;
          width: 70%;
          height: 4rem;
          overflow: scroll;
          border-left: 1px solid #fff;
          font-size: 0.7rem;
          color: #fff;
          text-align: left;
        }
      }
      .bottom {
        display: inline-flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        height: 3.5rem;
        div {
          padding-left: 1rem;
          width: 80%;
          color: #777777;
          font-size: 0.7rem;
          text-align: left;
        }
        button {
          margin-right: 1rem;
          width: 4rem;
          height: 1.5rem;
          font-size: 0.8rem;
          background-color: #fff;
          border: 1px solid #ff6666;
          border-radius: 20rem;
          color: #ff6666;
          outline: none;
        }
        img {
          position: absolute;
          right: 0;
          bottom: 0;
          width: 5rem;
          height: 5rem;
        }
      }
    }
  }
}
</style>
